package com.test;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.*;

public class UseRightButton extends JFrame implements MouseListener {
	JPanel panel;
	JLabel display;

	public UseRightButton() {
		setTitle("Use right button and popup menu");
		setSize(400, 300);
		panel = new JPanel();
		display = new JLabel(" ");
		display.setOpaque(true);
		display.setBackground(Color.yellow);
		panel.add(display);
		panel.addMouseListener(this);
		display.addMouseListener(this);
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(panel, BorderLayout.CENTER);
	}

	public static void main(String[] args) {
		UseRightButton rb = new UseRightButton();
		rb.setVisible(true);
	}

	public void mousePressed(MouseEvent e) {
		if (e.getSource() == panel && e.getButton() == MouseEvent.BUTTON1) {
			
//			MyPopupMenu popup = new MyPopupMenu(this);
//			popup.show((Component) panel, e.getX(), e.getY());
			System.out.println("2");
		} else if (e.getSource() == display
				&& e.getButton() == MouseEvent.BUTTON1) {
//			MyPopupMenu popup = new MyPopupMenu(this);
//			popup.show((Component) display, e.getX(), e.getY());
			
			
			System.out.println("1");
		}
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mouseClicked(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {
	}
}
